package com.team5101.controller;


import com.team5101.dao.INowFilmDao;
import com.team5101.entity.AllMoviesTimes;
import com.team5101.entity.NowFilm;
import com.team5101.entity.User;
import com.team5101.service.IHotFsService;
import com.team5101.utils.MD5;
import com.team5101.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.List;

/*
* auther:gc
* 上映电影的所有，和注册
*/

@Controller
@RequestMapping("/api/hotmovie")
public class HotFsController {
    @Autowired
    private INowFilmDao iNowFilmDao;

    @Autowired
    private IHotFsService iHotFsService;

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    @ResponseBody
    public R TestRegister(User user){
        String uPassWord = MD5.MD5Encode(user.getuPassword());
        user.setuPassword(uPassWord);
        //返回值为状态码
        Integer stu = iHotFsService.selectByphone(user);
        System.out.println("======"+stu);
        if (stu==null){ //如果状态码为空，证明手机号重复
            return R.error(600,"手机号码已被占用");
        }else if (stu==1){
            return R.ok(user); //状态码为1
        }
        return R.ok(user);
    }


    @RequestMapping("/selectOnMovies")
    @ResponseBody
    public R selectOnMovies(){     //首页点击热映电影，显示显示热映电影
        System.out.println("aaaaaa");
        List<NowFilm> onMovies = iHotFsService.selectOnMovies();
        return R.ok(onMovies);
    }

    @RequestMapping("/selectOneMovies")
    @ResponseBody
    public R selectOneMovies(Integer fnId){     //热映电影点击立即购买，显示当前电影信息
        NowFilm nowFilm = iHotFsService.selectOneMovies(fnId);
        return R.ok(nowFilm);
    }

    @RequestMapping("/getMoviesTimes")
    @ResponseBody
    public R selectMoviesTimes(Integer ofId, String sDay) throws ParseException {
        List<AllMoviesTimes> allMoviesTimes = iHotFsService.selectMoviesTimes(ofId, sDay);//进入购票页，默认查出当天的放映表
        return R.ok(allMoviesTimes);
    }
      //首页上映电影显示
    @RequestMapping("getfilmindex/{fnishow}")
    @ResponseBody
    public List<NowFilm>   getfilmindex(@PathVariable Integer fnishow){
        return  iHotFsService.selIndexHotMvs(fnishow);
    }


    @RequestMapping("/onepage")
    @ResponseBody
    public R sel(Integer currentPage){     //分页查询
        return R.ok(iHotFsService.selectOnePage(currentPage));
    }

    @RequestMapping("/sIndexHot")
    @ResponseBody
    public R sleIndexHotMvs(Integer fnIshow){  //获取首页热映电影
        List<NowFilm> nowFilms = iHotFsService.selIndexHotMvs(fnIshow);
        return R.ok(nowFilms);
    }




}
